package com.xindaoapp.henghua.view;

import java.io.Serializable;
import java.util.Map;

import com.xindaoapp.henghua.activity.ImagePagerActivity;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
/** 自定义LinearLayout*/
public class HSVLayout extends LinearLayout {

	private HSVAdapter adapter;
	private Context context;

	public HSVLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
	}

	public void setAdapter(final HSVAdapter adapter) {
		this.adapter = adapter;
		this.removeAllViews();
		for (int i = 0; i < adapter.getCount(); i++) {
			final Map<String, String> map = adapter.getItem(i);
			
			View view = adapter.getView(i, null, null);
			view.setPadding(10, 0, 10, 0);
			
			final int position = i ;
			// 为视图设定点击监听器
			view.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					
//					Toast.makeText(context, "您选择了" + (position+1),
//							Toast.LENGTH_SHORT).show();
					
					Intent intent = new Intent(context, ImagePagerActivity.class);
					intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, (Serializable)adapter.getUrls());
					intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
					context.startActivity(intent);

				}
			});
			this.setOrientation(HORIZONTAL);
			this.addView(view, new LinearLayout.LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		}
	}


}
